const {
    controller,
    get,
    post,
    put
} = require('../lib/decorator');
const { checkPassword } = require('../service/user');

@controller('/api/v0/user')
export class UserController {
    @post('/')
    async login (ctx, next) {
        const { email, password } = ctx.request.body;
        const matchData = await checkPassword(email, password);

        if (!matchData.user) {
            return (ctx.body = {
                code: 100,
                success: false,
                data: '用户不存在'
            })
        }

        if (matchData.match) {
            return (ctx.body = {
                code: 200,
                success: true,
                data: '成功'
            })
        }

        return (ctx.body = {
            code: 200,
            success: false,
            data: '账号密码错误'
        })
        await next();
    }
}